package com.ticket.api.service.Impl;

import com.ticket.common.time.CommonFunction;
import com.ticket.db.dao.TblMarketInfoMapper;
import com.ticket.db.entity.TblMarketInfo;
import com.ticket.api.service.TbMarketInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TbMarKetInfoSericeImpl implements TbMarketInfoService {

    @Autowired
    TblMarketInfoMapper tblMarketInfoMapper;

    @Override
    public List<TblMarketInfo> findTblMarketInfoByCondition(TblMarketInfo marketInfo) {
        return tblMarketInfoMapper.findMarketInfo(marketInfo);
    }

    @Override
    public boolean insertTblMarketInfo(TblMarketInfo marketInfo) {
        if(marketInfo==null){ return false; }
        TblMarketInfo info = new TblMarketInfo();
        info.setMarketId(marketInfo.getMarketId());
        TblMarketInfo mark = tblMarketInfoMapper.findTblMarketInfoByConditionNoNLike(info);
        if (mark != null) { return true; }
        String TimeData=  CommonFunction.getLocalTime14();
        marketInfo.setStatus("1");
        marketInfo.setCreateTime(TimeData);
        marketInfo.setLastUpdateUser(marketInfo.getCreateUser());
        marketInfo.setLastUpdateTime( CommonFunction.getLocalTime14());
        return tblMarketInfoMapper.insertTblMarketInfo(marketInfo);
    }

    @Override
    public boolean updateTblMarketInfo(TblMarketInfo marketInfo) {
        TblMarketInfo mark = new TblMarketInfo();
        mark.setMarketId(marketInfo.getMarketId());
        mark = tblMarketInfoMapper.findTblMarketInfoByConditionNoNLike(mark);
        if (mark == null) {
            return false;
        }
        marketInfo.setLastUpdateUser(marketInfo.getCreateUser());
        marketInfo.setLastUpdateTime( CommonFunction.getLocalTime14());
        return tblMarketInfoMapper.updateTblMarketInfo(marketInfo);
    }
}
